﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScriptBox.Services
{
    public class AppConfig
    {
        public bool AutoHideEnabled { get; set; } = false;
        public int HotkeyModifiers { get; set; } = 0x0001; // MOD_ALT
        public int HotkeyKey { get; set; } = 0xC0;        // VK_OEM_3
        public void Save()
        {
            var path = GetConfigPath();
            var directory = Path.GetDirectoryName(path);
            
            // 添加目录创建逻辑
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            var json = JsonConvert.SerializeObject(this);
            File.WriteAllText(path, json);
        }

        public static AppConfig Load()
        {
            var path = GetConfigPath();
            return File.Exists(path) ?
                JsonConvert.DeserializeObject<AppConfig>(File.ReadAllText(path)) :
                new AppConfig();
        }

        private static string GetConfigPath() =>
            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
            "ScriptBox", "config.json");
    }
}
